package com.juego.utilidades;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.Animator.AnimatorListener;
import android.os.Handler;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.juego.male.R;

public class Animaciones {

	public void flipCarta(final ImageView carta, final int id, final boolean eSsplash){
		ObjectAnimator flip  = ObjectAnimator.ofFloat(carta, "rotationX", 180f, 90f);		
		flip.setDuration(1000);
		flip.setInterpolator(new LinearInterpolator());
		flip.start();
		flip.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animator animation) {


			}

			@Override
			public void onAnimationEnd(Animator animation) {				
				carta.setImageResource(id);
				animation  = ObjectAnimator.ofFloat(carta, "rotationX", 90f, 0f);	
				if (eSsplash){
					animation.setDuration(1000);
				}else{
					animation.setDuration(500);
				}
				animation.setInterpolator(new LinearInterpolator());
				animation.start();
				if (eSsplash){
					new Handler().postDelayed(new Runnable() {

						@Override
						public void run() {
							carta.setBackgroundResource(R.drawable.sh_pierde);
							carta.setRotation(15);

						}
					}, 2000);
				}								
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		
	}

}
